package com.sl.camera_demo

import android.util.Log
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry

class AuthCut(var registry: BinaryMessenger) : MethodChannel.MethodCallHandler {

    val methodChannel: MethodChannel by lazy {
        MethodChannel(registry, "sl.cutAuthImage")
    }

    init {
        methodChannel.setMethodCallHandler(this)
    }

    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
        when (call.method) {
            "cutAuth" -> {
                var imgViewCutRect = CutRect()
                imgViewCutRect.run {
                    startX = call.argument<Double>("imgViewCutRectStartX")!!
                    startY = call.argument<Double>("imgViewCutRectStartY")!!
                    width = call.argument<Double>("imgViewCutRectWidth")!!
                    height = call.argument<Double>("imgViewCutRectHeight")!!
                }
                var borderViewCutRect = CutRect()
                borderViewCutRect.run {
                    startX = call.argument<Double>("borderViewCutRectStartX")!!
                    startY = call.argument<Double>("borderViewCutRectStartY")!!
                    width = call.argument<Double>("borderViewCutRectWidth")!!
                    height = call.argument<Double>("borderViewCutRectHeight")!!
                }
                Log.d("imgViewCutRect", imgViewCutRect.toString())
                Log.d("borderViewCutRect", borderViewCutRect.toString())
                BitmapCutUtil(call.argument<String>("path")!!,imgViewCutRect,borderViewCutRect,result).run {
                    initBitmap()
                    dealBitMap()
                }
            }
        }
    }

}
